<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>订单</title>
<link rel="stylesheet" type="text/css" href="/style/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/swiper.min.css"/>
<link rel="stylesheet" type="text/css" href="/style/css/xshop.css?ver=20190812" />
<link rel="stylesheet" type="text/css" href="/style/css/fu.shop.css?ver=20190812"/>
<script src="/style/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/js/xShop.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
<link href="/style/css/dropload.css" rel="stylesheet">
<script src="/style/js/dropload.js"></script>
<style>
.foot-menu ul{ height: 1rem;line-height: 1rem; }
.outer{position:absolute;left:0;width:100%;height:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-ms-flex-direction:column;-webkit-box-orient:vertical;box-orient:vertical;-webkit-flex-direction:column;flex-direction:column}
.inner{-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;background-color:#f1f1f1;overflow-y:scroll;-webkit-overflow-scrolling:touch; margin-bottom: 1.2rem;}
.inner.iPhoneX
{
    margin-bottom: 1.6rem;
}
.opacity{-webkit-animation:opacity .3s linear;animation:opacity .3s linear}
@-webkit-keyframes opacity{0%{opacity:0}
100%{opacity:1}
}
@keyframes opacity{0%{opacity:0}
100%{opacity:1}
}
.popmask{position:fixed;width:100%;height:100%;background:rgba(0,0,0,.8);left:0;top:0;z-index:999;display: none;}
.popexp{position:fixed;width:80%;height:70%;padding:10% 5%;left:5%;top:5%;background:#fff;z-index:1000;overflow-x:hidden;overflow-y:auto;display: none;}
.popexp .name{float:left;width:100%;height:auto;color:#999;padding-bottom:.3rem;line-height:.4rem;font-size:.26rem;border-bottom:1px solid #ccc;margin-bottom:.5rem}
.popexp ul{float:left;width:100%;height:auto;list-style:none}
.popexp ul li{border-left:1px solid #ccc;height:auto;background:#fff;color:#999;float:left;width:80%;padding-left:.5rem;font-size:.26rem}
.popexp ul li div{position:absolute;width:.2rem;height:.2rem;border-radius:.2rem;background:#ccc;left:.28rem}
.popexp ul li.curr{color:#73C887}
.popexp ul li.curr div{position:absolute;width:.25rem;height:.25rem;border-radius:.25rem;background:#73C887;border:.05rem solid #D1ECD9;left:.22rem}
.popexp ul li p{padding-top:.2rem}
.popexp ul li i{float:left;width:100%;height:1px;background:#ccc;margin:.2rem 0}
.popclose{position: fixed; bottom: 1rem; text-align: center; width: 100%; height: .5rem; z-index: 1000; display: none;}
.popclose img{width: auto; height: .8rem;}
</style>
</head>
<body>
<div class="outwrap">
		<!--top-->	
  	<!-- <div class="topbar clearfix topvh">
    <a href="/user/index" class="btn-back">
        <i class="ico-back"></i><span>返回</span>
    </a>
			<h2 class="title">订单</h2>
		</div> -->

    <div class="meinner-adr-add">
    <div class="ord-header ord-nav">
      <div class="me-myor">
        <ul class="clearfix">
          <li data-type="0" class="_order_list <?php if(empty($this->type)){ echo "on";}?>" >
            <a href="javascript:;">
                <i class="ico">
                    <img src="/style/wei/images/me/or-1.png">
                    <?php if($this->order['order_count']>0):?>
                <em><?=$this->order['order_count'];?></em>
                <?php endif;?></i>
                <p>全部订单</p>
            </a>
        </li>
          <li data-type="1" class="_order_list <?php if($this->type ==1){ echo "on";}?>"">
            <a href="javascript:;"><i class="ico"><img src="/style/wei/images/me/or-2.png"><?php if($this->order['not_pay_count']>0):?><em><?=$this->order['not_pay_count'];?></em><?php endif;?></i><p>待付款</p></a></li>
          <li data-type="2" class="_order_list <?php if($this->type ==2){ echo "on";}?>"">
            <a href="javascript:;">
                <i class="ico"><img src="/style/wei/images/me/or-3.png"><?php if($this->order['send_count']>0):?><em><?=$this->order['send_count'];?></em><?php endif;?></i><p>待发货</p></a></li>
          <li data-type="3" class="_order_list <?php if($this->type ==3){ echo "on";}?>""><a href="javascript:;">
            <i class="ico"><img src="/style/wei/images/me/or-4.png"><?php if($this->order['sended_count']>0):?><em><?=$this->order['sended_count'];?></em><?php endif;?></i><p>待收货</p></a></li>
          <!-- <li data-type="5" class="_order_list <?php if($this->type ==5){ echo "on";}?>""><a href="javascript:;"><i class="ico"><?php if($this->order['rebackapply_count']>0):?><em><?=$this->order['rebackapply_count'];?></em><?php endif;?></i><p>退货退款</p></a></li> -->
        </ul>
      </div>
    </div>
    <?php if(empty($this->data['data'])):?>
      <div class="order-none">
        <i class="ico"><img src="/style/images/noorder1.png"/></i>       
        <p class="p1">您还没有相关的订单</p>
        <p class="p2">可以去看看有哪些想买的</p>
        <a href="/" class="goshop">去选购</a>
      </div>
      <?php else:?>
        <div class="outer ord-main">
         <div class="inner">
         <div id="thelist">
          <?php foreach($this->data['data'] as $v):?>
        <div class="ord-list">
      <div class="bh"><p>订单编号：<?=$v['order_sn']?></p>
      </div>
      <div class="info">
        <dl><dt>状态：</dt><dd class="state"><span><?=$v['new_status']?></span></dd></dl>
        <dl><dt>时间：</dt><dd><?=date("Y-m-d H:i:s",$v['add_time'])?></dd></dl>        
        <dl><dt>优惠券抵用：</dt><dd>￥<?=$v['discount_fee'];?></dd></dl>  
        <dl><dt>硒米消费：</dt><dd><?=($v['ximi_fee']*1);?></dd></dl>        
        <dl><dt>金花抵用：</dt><dd>￥<?=($v['gold_fee']*1);?></dd></dl>       
        <dl><dt>代金券抵用：</dt><dd>￥<?=$v['coupon_fee'];?></dd></dl>        
        <dl><dt>收货人：</dt><dd><?=$v['consignee']?></dd></dl>
        <dl><dt>电话：</dt><dd><?=$v['mobile']?></dd></dl>
        <dl><dt>地址：</dt><dd><?=$this->data['region'][$v['province_id']]?><?=$this->data['region'][$v['city_id']]?><?= !empty($v['county_id'])?$this->data['region'][$v['county_id']]:'';?><?=$v['address']?></dd></dl> 
         <?php if(!empty($v['remark'])){?><dl><dt>备注：</dt><dd style="color:#f6b804"><?=$v['remark']?></dd></dl><?php }?> 
      </div>
      <div class="splist">
        <ul>
        <?php $num=0;  if(!empty($v['goods'])){ ?>
        <?php foreach($v['goods'] as $vv): $num+=$vv['goods_number'];?>
          <li class="clearfix">
          <a href="/order/orderdetail?order_id=<?=$v['order_id']?>">
            <div class="img"><img src="<?=$this->data['docs'][$vv['thumb_docid']]?>"/></div>
            <div class="goods_msg clearfix">
              <h2><?=$vv['goods_name']?><?=$vv['attr_str']?></h2>
              <div class="prc">
                <span><?php
                if($vv['goods_price']>0)
                {
                    echo '￥'.$vv['goods_price'];
                }
                elseif($vv['ximi_price']>0)
                {
                    echo ($vv['ximi_price']*1).'硒米';
                }
                ?></span><em>数量 <?=$vv['goods_number']?></em>                
              </div>
            </div>
            </a>
            <?php
            if($vv['shipping_id']!="")
            {
              echo '<div class="express"><div data-shipping="'.$vv['shipping_id'].'" data-shipping-name="'.$vv['shipping_name'].'">查看物流</div></div>';
            }
            ?>            
          </li>
        <?php endforeach;?>
          <?php }?>
        </ul>       
      <div class="gongji clearfix">
        <span class="num">共<?=$num;?>件商品</span>
        <span class="num">运费: ￥<?=$v['shipping_fee'];?></span>
        <span class="price">合计: ￥<?=$v['pay_fee'];?></span>
       </div>
        <div class="btns">
        <?php if($v['new_status']=='待发货'):?>
        <?php elseif($v['new_status']=='待收货'):?>
                    <a href="javascript:void(0)" class="color" onClick="receive_order(<?=$v['order_id']?>);">确认收货</a>
                   
        <?php elseif($v['new_status']=='待付款'):?>
         <?php if($v['sell_type'] !=4){?>           
                <a href="javascript:void(0)" class="cancel" onClick="cancle_order(<?=$v['order_id']?>)">取消订单</a>
               <?php }?> 
                <a href="javascript:void(0)" class="color" onClick="_gotopay(<?=$v['order_id']?>)">付款</a>

        <?php endif;?>


         </div>
      </div>
    </div>
      <?php endforeach;?>
      </div>
      </div>
      </div>
      <?php endif;?>
  </div>
  

</div>
<div class="popmask"></div>
<div class="popexp">
  <div class="name">--</div>
  <ul></ul>
</div>
<div class="popclose"><img src="/style/images/close.png"></div>

<!--底部导航-->
<div class="foot-menu">
    <ul class="clearfix">
        <a href="/"><li><i class="ico-7"></i><span>首页</span></li></a>
        <a href="/rcm"><li><i class="ico-1"></i><span>商城</span></li></a>
        <a href="/cart/cart"><li><i class="ico-5"></i><span>购物车</span></li> </a>  
        <a href="/college"><li><i class="ico-8"></i><span>商学院</span></li></a>  
        <a href="/user/index"><li class="on"><i class="ico-4"></i><span>我的</span></li> </a>    
    </ul>
</div>

<script type="text/javascript">  
$(document).ready(function(e) {
    // 查看物流信息
    _refresh_bind_express();
    // 关闭物流信息窗口
    $(".popclose").on("click", function() {
        $(".popmask,.popexp,.popclose").css("display", "none");
    });
});

function _showExpress(shipping_id, shipping_name) {
    if (shipping_id != "" && shipping_name != "") {
        $.post("/order/ajax", {
            "act": "getexpress",
            "shipping_id": shipping_id,
            "shipping_name": shipping_name,
            "mr": Math.random(),
        }, function(json) {
            console.log(json);
            if (json.code == 200) {
                $(".popmask,.popexp,.popclose").css("display", "block");
                $(".popexp .name").html('快递公司：' + json.data.shipping_name + '<br>快递单号：' + json.data.shipping_id);
                $(".popexp ul").empty();
                if (typeof json.data.info != "undefined" && json.data.info != null) {
                    var _cls = _line = '';
                    $.each(json.data.info, function(i, v) {
                        if (i == 0) {
                            _cls = ' class="curr"';
                        } else {
                            _cls = '';
                        }
                        if (i + 1 < json.data.info.length) {
                            _line = '<i></i>';
                        } else {
                            _line = '';
                        }
                        $(".popexp ul").append('<li' + _cls + '><div></div>' + v['StatusDescription'] + '<p>' + v['Date'] + '</p>' + _line + '</li>');
                    });
                }
            }
            else
            {
              swal("暂未查到物流信息");
            }
        }, "json");
    }
}

function _gotopay(order_id) {
    window.location.href = '/order/pay?code=200&order_id=' + order_id;
}
// 确认收货
function receive_order(order_id) {
    swal({
        title: "确定收到货了吗？",
        type: "warning",
        timer: 30000,
        showCancelButton: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnConfirm: false,
        closeOnCancel: true
    }, function(isConfirm) {
        if (isConfirm) {
            $.ajax({
                type: "POST",
                url: "/order/ajax",
                data: {
                    "act": "receive_order",
                    "order_id": order_id,
                    "mr": Math.random()
                },
                dataType: "json",
                success: function(data) {
                    if (data.code == 200) {
                        swal("确认收货成功!", false, "success");
                        setTimeout(function() {
                            location.href = '/order/order?type=4';
                        }, 2100);
                    } else {
                        swal("确认收货失败，请重试", false, "error");
                    }
                }
            });
        }
    });
}
// 取消订单
function cancle_order(order_id) {
    swal({
        title: "确定取消订单吗？",
        type: "warning",
        timer: 30000,
        showCancelButton: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnConfirm: false,
        closeOnCancel: true
    }, function(isConfirm) {
        if (isConfirm) {
            $.ajax({
                type: "POST",
                url: "/order/ajax",
                data: {
                    "act": "cancel_order",
                    "order_id": order_id,
                    "mr": Math.random()
                },
                dataType: "json",
                success: function(json) {
                    console.log(json)
                    if (json.code == 200) {
                        swal("取消订单成功", false, "success");
                        setTimeout(function() {
                            window.location.reload();
                        }, 2100);
                    } else {
                        swal("取消订单失败，请重试", false, "error");
                    }
                }
            }, "json");
        }
    });
}
var _type = <?=$this->type >0 ? $this->type : 0;?>;
$('._order_list').click(function() {
    $('.dropload-load').hide();
    $('.dropload-refresh').hide();
    _type = $(this).attr('data-type');
    $('._order_list').removeClass('on');
    $(this).addClass('on');
    order_ajax();
})
var is_pat = <?=$this->is_pat >0 ?$this->is_pat:0;?>;
function order_ajax() {
    $.ajax({
        type: "get",
        url: "/order/order_ajax?is_pat="+is_pat,
        data: {
            "type": _type,
            "mr": Math.random()
        },
        async: false,
        dataType: 'json',
        success: function(data) {
            shtml = "";
            ii = 0;
            if (data.data.length > 0) {
                $(data.data).each(function(i, v) {
                    ii++;
                    var county_id;
                    if(v.county_id>0){
                    	county_id = data.region[v.county_id];
                        }else{
                        	county_id= "";
                         }
                    shtml += ' <div class="ord-list"><div class="bh"><p>订单编号：' + v.order_sn + '</p></div><div class="info"><dl><dt>状态：</dt><dd class="state"><span>' + v.new_status + '</span></dd></dl><dl><dt>时间：</dt><dd>' + v.create_time + '</dd></dl><dl><dt>优惠券抵用：</dt><dd>￥'+v.discount_fee+'</dd></dl><dl><dt>硒米消费：</dt><dd>'+(v.ximi_fee*1)+'</dd></dl>        <dl><dt>金花抵用：</dt><dd>￥'+(v.gold_fee*1)+'</dd></dl><dl><dt>代金券抵用：</dt><dd>￥'+v.coupon_fee+'</dd></dl><dl><dt>收货人：</dt><dd>' + v.consignee + '</dd></dl><dl><dt>电话：</dt><dd>' + v.mobile + '</dd></dl><dl><dt>地址：</dt><dd>' + data.region[v.province_id] + data.region[v.city_id] + county_id + v.address + '</dd></dl>';
                    if (v.remark != '' && v.remark != null) shtml += '<dl><dt>备注：</dt><dd style="color:#f6b804">' + v.remark + '</dd></dl>';
                    shtml += '</div><div class="splist"><ul>';
                    num = 0;
                    if (v.goods != '' && v.goods != null) {
                        $(v.goods).each(function(ii, vv) {
                            num += parseInt(vv.goods_number);
                            if (vv.shipping_id) {
                                shipping_id = '<div class="express"><div data-shipping="' + vv.shipping_id + '" data-shipping-name="' + vv.shipping_name + '">查看物流</div></div>';
                            } else {
                                shipping_id = "";
                            }

                            if(vv.ximi_price >0)
                            {
                                vv.goods_price = (vv.ximi_price*1) + '硒米';
                            }
                            else
                            {
                                vv.goods_price = '￥'+vv.goods_price;
                            }

                            shtml += '<li class="clearfix"><a href="/order/orderdetail?order_id=' + v.order_id + '"><div class="img"><img src="' + data.docs[vv.thumb_docid] + '"/></div><div class="goods_msg clearfix"><h2>' + vv.goods_name + '</h2><div class="prc"><span>' + vv.goods_price + '</span><em>数量 ' + vv.goods_number + '</em></div></div></a>' + shipping_id + '</li>';
                        });
                    }
                    shtml += '</ul><div class="gongji clearfix"><span class="num">共' + num + '件商品</span> <span class="num">运费: ￥' + v.shipping_fee + '</span><span class="price">合计: ￥' + v.pay_fee + '</span></div><div class="btns">';
                    if (v['new_status'] == '待收货') shtml += ' <a href="javascript:void(0)" class="color" onClick="receive_order(' + v.order_id + ');">确认收货</a>';
                    else if (v['new_status'] == '待付款') shtml += '  <a href="javascript:void(0)" class="cancel" onclick="cancle_order(' + v.order_id + ')">取消订单</a> <a href="javascript:void(0)" class="color" onclick="_gotopay(' + v.order_id + ')">付款</a>';
                    shtml += '</div></div></div>';
                });
                $("#thelist").html(shtml);
                _refresh_bind_express();
            } else {
                var htmlss = '';
                htmlss += '<div class="order-none">';
                htmlss += '<i class="ico"><img src="/style/images/noorder1.png"/></i>';
                htmlss += '<p class="p1">您还没有相关的订单</p>';
                htmlss += '<p class="p2">可以去看看有哪些想买的</p>';
                htmlss += '<a href="/" class="goshop">去选购</a></div>';
                //$(".meinner-adr-add").append();
                $("#thelist").html(htmlss);
            }
        }
    });
}

function _refresh_bind_express() {
    // 查看物流信息
    $(".express div").unbind();
    $(".express div").bind("click", function() {
        var _shipping_id = $(this).attr("data-shipping");
        var _shipping_name = $(this).attr("data-shipping-name");
        if (_shipping_id != "" && _shipping_name != "") {
            _showExpress(_shipping_id, _shipping_name);
        }
    });
}
$(document).ready(function() {
    //加载分页
    var p = 1;
    var counter1 = 1;
    var dropload = $('.inner').dropload({
        loadDownFn: function(me) {
            p = parseInt(p) + 1;
            $.ajax({
                type: "get",
                url: "/order/order_ajax?is_pat="+is_pat,
                data: {
                    "type": _type,
                    "page": p,
                    "mr": Math.random()
                },
                async: false,
                dataType: 'json',
                success: function(data) {
                    shtml = "";
                    ii = 0;
                    if (data.data.length > 0) {
                        $(data.data).each(function(i, v) {
                            ii++;
                            var county_id;
                            if(v.county_id>0){
                                county_id = data.region[v.county_id];
                                }else{
                                    county_id= "";
                                 }
                            shtml += ' <div class="ord-list"><div class="bh"><p>订单编号：' + v.order_sn + '</p></div><div class="info"><dl><dt>状态：</dt><dd class="state"><span>' + v.new_status + '</span></dd></dl><dl><dt>时间：</dt><dd>' + v.create_time + '</dd></dl><dl><dt>硒米消费：</dt><dd>'+(v.ximi_fee*1)+'</dd></dl>        <dl><dt>金花抵用：</dt><dd>￥'+(v.gold_fee*1)+'</dd></dl><dl><dt>代金券抵用：</dt><dd>￥'+v.coupon_fee+'</dd></dl><dl><dt>收货人：</dt><dd>' + v.consignee + '</dd></dl><dl><dt>电话：</dt><dd>' + v.mobile + '</dd></dl><dl><dt>地址：</dt><dd>' + data.region[v.province_id] + data.region[v.city_id] + county_id + v.address + '</dd></dl>';
                            if (v.remark != '' && v.remark != null) shtml += '<dl><dt>备注：</dt><dd style="color:#f6b804">' + v.remark + '</dd></dl>';
                            shtml += '</div><div class="splist"><ul>';
                            num = 0;
                            if (v.goods != '' && v.goods != null) {
                                $(v.goods).each(function(ii, vv) {
                                    num += parseInt(vv.goods_number);
                                    if (vv.shipping_id) {
                                        shipping_id = '<div class="express"><div data-shipping="' + vv.shipping_id + '" data-shipping-name="' + vv.shipping_name + '">查看物流</div></div>';
                                    } else {
                                        shipping_id = "";
                                    }

                                    if(vv.ximi_price >0)
                                    {
                                        vv.goods_price = (vv.ximi_price*1) + '硒米';
                                    }
                                    else
                                    {
                                        vv.goods_price = '￥'+vv.goods_price;
                                    }

                                    shtml += '<li class="clearfix"><a href="/order/orderdetail?order_id=' + v.order_id + '"><div class="img"><img src="' + data.docs[vv.thumb_docid] + '"/></div><div class="goods_msg clearfix"><h2>' + vv.goods_name + '</h2><div class="prc"><span>' + vv.goods_price + '</span><em>数量 ' + vv.goods_number + '</em></div></div></a>' + shipping_id + '</li>';
                                });
                            }
                            shtml += '</ul><div class="gongji clearfix"><span class="num">共' + num + '件商品</span> <span class="num">运费: ￥' + v.shipping_fee + '</span><span class="price">合计: ￥' + v.pay_fee + '</span></div><div class="btns">';
                            if (v['new_status'] == '待收货') shtml += ' <a href="javascript:void(0)" class="color" onClick="receive_order(' + v.order_id + ');">确认收货</a>';
                            else if (v['new_status'] == '待付款') shtml += '  <a href="javascript:void(0)" class="cancel" onclick="cancle_order(' + v.order_id + ')">取消订单</a> <a href="javascript:void(0)" class="color" onclick="_gotopay(' + v.order_id + ')">付款</a>';
                            shtml += '</div></div></div>';
                        });
                        $("#thelist").append(shtml);
                        _refresh_bind_express();
                        me.resetload();
                    } else {
                        me.lock();
                        me.noData();
                        me.resetload();
                        $(".dropload-down").hide();
                    }
                }
            });
        }
    });
    $('.dropload-load').hide();
});
</script>
</body>
</html>